package com.sky.happygos.common.YiChart;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sky.happygos.R;
import com.sky.happygos.utils.DensityUtil;

/**
 * Created by qqqqqqq on 2017/4/23.
 */

public class ChartItem extends RelativeLayout{
    LayoutInflater layoutInflater;
    LineView lineView;
    RelativeLayout bg;
    TextView title;

    Paint mPaint;

    public ChartItem(Context context) {
        super(context);
        init();
    }

    public ChartItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ChartItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void init(){
        setWillNotDraw(false);
        setBackgroundResource(R.color.bg_statiscs);
        layoutInflater = LayoutInflater.from(getContext());
        initBg();
        initLine();
    }

    private void initBg(){
        bg = (RelativeLayout) layoutInflater.inflate(R.layout.item_chart,null);
        title = (TextView) bg.findViewById(R.id.chart_title);
        bg.setLayoutParams(new RelativeLayout.LayoutParams(DensityUtil.dip2px(getContext(),40), ViewGroup.LayoutParams.MATCH_PARENT));
        addView(bg);
    }
    private void initLine(){
        lineView = new LineView(getContext());
        lineView.setLayoutParams(new RelativeLayout.LayoutParams(DensityUtil.dip2px(getContext(),40), ViewGroup.LayoutParams.MATCH_PARENT));
        addView(lineView);
    }

    public void setTitle(String title){
        this.title.setText(title);
    }

    public void setData(int preValue,int curalue,int nextValue){
        lineView.setData(preValue,curalue,nextValue);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
